//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "ChfLiborSwapIsdaFix.h"
using namespace Cephei::QL::Indexes::Swap;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Indexes/SwapIndex.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Instruments/VanillaSwap.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
using namespace Cephei::QL::Instruments;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (Cephei::QL::Times::IPeriod^ tenor, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ h) : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
    CPeriod^ _Ctenor;
    CYieldTermStructure^ _Ch;
    try
    {
#ifdef HANDLE
        _phChfLiborSwapIsdaFix = NULL;
#endif
        _Ctenor = safe_cast<CPeriod^> (tenor);
        _Ctenor->Lock();
        QuantLib::Period& _tenor = static_cast<QuantLib::Period&> (_Ctenor->GetReference ()); 
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>::IsSome::get (h))
        {
            _Ch = safe_cast<CYieldTermStructure^> (h->Value);
            _Ch->Lock();
        }
        Handle<QuantLib::YieldTermStructure>& _h = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>::IsSome::get (h) ? static_cast<Handle<QuantLib::YieldTermStructure>&> (_Ch->GetHandle ()) : Handle<QuantLib::YieldTermStructure>()); //1
        _ppChfLiborSwapIsdaFix = new boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix> (new QuantLib::ChfLiborSwapIsdaFix ( _tenor,  _h ));
        SetSwapIndex (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppChfLiborSwapIsdaFix));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ctenor != nullptr) _Ctenor->Unlock();
        if (_Ch != nullptr) _Ch->Unlock();
    }
}
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix>& childNative, Object^ owner) : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
#ifdef HANDLE
	_phChfLiborSwapIsdaFix = NULL;
#endif
	_ppChfLiborSwapIsdaFix = &childNative;
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppChfLiborSwapIsdaFix));
}
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (QuantLib::ChfLiborSwapIsdaFix& childNative, Object^ owner) : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
#ifdef HANDLE
	_phChfLiborSwapIsdaFix = NULL;
#endif
	_ppChfLiborSwapIsdaFix = new boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix> (&childNative);
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppChfLiborSwapIsdaFix));
    _ChfLiborSwapIsdaFixOwner = owner;
    _SwapIndexOwner = owner;
}

Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (CChfLiborSwapIsdaFix^ copy) : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
#ifdef HANDLE
	_phChfLiborSwapIsdaFix = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppChfLiborSwapIsdaFix = new boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix> (copy->GetShared());
        _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppChfLiborSwapIsdaFix));
    }
}
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (System::Type^ t) : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
#ifdef HANDLE
	_phChfLiborSwapIsdaFix = NULL;
#endif
	if (!t->IsSubclassOf(CChfLiborSwapIsdaFix::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (QuantLib::Handle<QuantLib::ChfLiborSwapIsdaFix>& childNative, Object^ owner)  : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
	_phChfLiborSwapIsdaFix = &childNative;
	_ppChfLiborSwapIsdaFix = &static_cast<boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix>>(childNative.currentLink());
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppChfLiborSwapIsdaFix));
    _ChfLiborSwapIsdaFixOwner = owner;
}
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (QuantLib::Handle<QuantLib::ChfLiborSwapIsdaFix> childNative)  : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
	_phChfLiborSwapIsdaFix = &childNative;
	_ppChfLiborSwapIsdaFix = &static_cast<boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix>>(childNative.currentLink());
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppChfLiborSwapIsdaFix));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::CChfLiborSwapIsdaFix (QuantLib::ChfLiborSwapIsdaFix childNative)  : CSwapIndex(CChfLiborSwapIsdaFix::typeid)
{
#ifdef HANDLE
	_phChfLiborSwapIsdaFix = NULL;
#endif
	_ppChfLiborSwapIsdaFix = new boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix> (new QuantLib::ChfLiborSwapIsdaFix (childNative));
    _ppSwapIndex = new boost::shared_ptr<QuantLib::SwapIndex> (boost::dynamic_pointer_cast<QuantLib::SwapIndex> (*_ppChfLiborSwapIsdaFix));
}
#endif

Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::~CChfLiborSwapIsdaFix ()
{
    if (_ppChfLiborSwapIsdaFix != NULL)
    {
	    delete _ppChfLiborSwapIsdaFix;
        _ppChfLiborSwapIsdaFix = NULL;
    }
}
Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::!CChfLiborSwapIsdaFix ()
{
    if (_ppChfLiborSwapIsdaFix != NULL)
    {
	    delete _ppChfLiborSwapIsdaFix;
    }
}
QuantLib::ChfLiborSwapIsdaFix& Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::GetReference ()
{
    if (_ppChfLiborSwapIsdaFix == NULL) throw gcnew NativeNullException ();
	return **_ppChfLiborSwapIsdaFix;
}
boost::shared_ptr<QuantLib::ChfLiborSwapIsdaFix>& Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::GetShared ()
{
    if (_ppChfLiborSwapIsdaFix == NULL) throw gcnew NativeNullException ();
	return *_ppChfLiborSwapIsdaFix;
}
QuantLib::ChfLiborSwapIsdaFix* Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::GetPointer ()
{
    if (_ppChfLiborSwapIsdaFix == NULL) throw gcnew NativeNullException ();
	return &**_ppChfLiborSwapIsdaFix;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ChfLiborSwapIsdaFix>& Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::GetHandle ()
{
	if (_phChfLiborSwapIsdaFix == NULL)
	{
		_phChfLiborSwapIsdaFix = new Handle<QuantLib::ChfLiborSwapIsdaFix> (*_ppChfLiborSwapIsdaFix);
	}
	return *_phChfLiborSwapIsdaFix;
}
#endif
bool Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix::HasNative () 
{
	return (_ppChfLiborSwapIsdaFix != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Indexes::Swap::IChfLiborSwapIsdaFix^ Cephei::QL::Indexes::Swap::CChfLiborSwapIsdaFix_Factory::Create (Cephei::QL::Times::IPeriod^ tenor, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYieldTermStructure^>^ h)
{
    return gcnew CChfLiborSwapIsdaFix ( tenor,  h);
}
